package org.game.db.proxy.bean;

import java.util.HashMap;
import java.util.Map;

import org.cfg.GrowUpCfg;
import org.cfg.HeroCfg;
import org.cfg.cache.GrowUpCfgCache;
import org.cfg.cache.HeroCfgCache;
import org.constant.smallkey.PlayerDataSmallKey;
import org.game.cache.ServerCache;
import org.game.db.bean.Hero;
import org.game.db.bean.Player;
import org.game.db.bean.Role;
import org.game.db.cache.RoleCache;
import org.game.db.vo.EquipmentVO;
import org.game.db.vo.SkinVO;
import org.game.manager.PlayerManager;

import com.google.common.collect.Maps;
import com.sojoys.artifact.build.data.base.BasePojoProxy;

/**
 * @author : DengYing
 * @CreateDate : 2017年11月30日 下午2:27:08
 * @Description ：英雄扩展
 */
public class HeroProxy extends BasePojoProxy<HeroProxy, Hero>{
	/**
	 * 战斗力
	 */
	private int fightPower = 0;
	/**
	 * 属性
	 */
	private Map<Integer, Integer> attr = new HashMap<>(40);
	/**
	 * 穿戴的装备信息<位置,装备>
	 */
	private Map<Integer, EquipmentVO> equipment = Maps.newHashMap();
	
	/**
	 * 已经使用技能点数
	 */
	private int alreadyUseSkillPiont = 0;

	/**
	 * 装备皮肤Id
	 */
	private SkinVO skinVo ;
	
	public Map<Integer, Integer> getAttr() {
		return attr;
	}

	public void setAttr(Map<Integer, Integer> attr) {
		this.attr = attr;
	}

	public HeroCfg getConfig() {
		return HeroCfgCache.me().getById(t.getCid());
	}

	public Map<Integer, EquipmentVO> getEquipment() {
		return equipment;
	}

	public void setEquipment(Map<Integer, EquipmentVO> equipment) {
		this.equipment = equipment;
	}

//	/**
//	 * 取得天使技能点上限
//	 * @return
//	 */
//	public int getMaxSkillPoint(){
//		return getConfig().getSkillPoint()[t.getAdvancedLvl()];
//	}

	public int getAlreadyUseSkillPiont() {
		return alreadyUseSkillPiont;
	}

	public void setAlreadyUseSkillPiont(int alreadyUseSkillPiont) {
		this.alreadyUseSkillPiont = alreadyUseSkillPiont;
	}
	
	/**
	 * 英雄的真实品质=进阶次数+配置品质
	 * @return
	 */
	public int getQuality(){
		return t.getUpQuality() + getConfig().getRarity();
	}
	
	/**
	 * 英雄的真实品质=进阶次数+配置品质
	 * @return
	 */
	public int getMaxLvl(){
		int growUpId =  getConfig().getAttribute() * 100 + t.getAdvancedLvl();
		GrowUpCfg growUp = GrowUpCfgCache.me().getById(growUpId);
		return growUp.getToplimit();
	}

	/**
	 * 获取关联精灵
	 */
	public Role getRelevantRole(){
		int roleCid = getConfig().getRole();
		return RoleCache.me().getByCidPlayerId(roleCid,t.getPlayerId());
	}

	public int getFightPower() {
		return fightPower;
	}

	public void changeFightPower(int fightPower) {
		// 战力没有变化
		if (this.fightPower == fightPower) {
			return;
		}
		Player player = t.getPlayerPkPlayerId();
		this.fightPower = fightPower;
		
		PlayerDataProxy dataProxy = PlayerManager.me().getDataProxy(player);
		int helpFightHeroCid = dataProxy.getDiscreteVO().getHelpFigntHeroCid();
		if(helpFightHeroCid == t.getCid()){
			Map<Integer, Object> map = Maps.newHashMap();
			map.put(org.bean.PlayerInfo.FIGHT_POWER, fightPower);
			ServerCache.getPlayerInfoByPid(player.getId()).upload(map);
		}
	}

	public SkinVO getSkinVo() {
		return skinVo;
	}

	public void setSkinVo(SkinVO skinVo) {
		this.skinVo = skinVo;
	}

	public boolean checkSkinId(int skinId){
		for (int id : getConfig().getOptionalSkin()) {
			if (id == skinId)
				return true;
		}
		return false;
	}
}
